#include "zf_common_headfile.h"

uint32 flash_memory[data_num];

int16 init_value = 0;

// int -> float
float ex_int2float (long int value)
{
    union
    {
        float float_value;
        unsigned long int_value;
    } c;

    c.int_value = value;
    return c.float_value;
}

// float -> long
long int ex_float2int (float value)
{
    union
    {
        float float_value;
        unsigned long int_value;
    } c;
    c.float_value = value;
    return c.int_value;
}

// flash读
void paraflash_read (void)
{
    register short i, j;
    unsigned char num;

    flash_read_page(0, 0, flash_memory, data_num);

    for (i = 0; i < ROWS; i++)
    {
        num = amenu2_init_pfc[i](FLASH_INIT);
        switch (menu2_mode)
        {
        case PARASET_F :
            for (j = 0; j < num; j++)
                *floatvalue[j] = ex_int2float(flash_memory[i * MAX_MENU2_NUM + j]);
            break;
        case PARASET_S :
            for (j = 0; j < num; j++)
                *intvalue[j] = flash_memory[i * MAX_MENU2_NUM + j];
            break;
        }
    }
}

// flash 写
void flash_memory_write (void)
{
    register short i, j;
    unsigned char num;

    for (i = 0; i < ROWS; i++)
    {
        num = amenu2_init_pfc[i](FLASH_INIT);
        switch (menu2_mode)
        {
        case PARASET_F :
            for (j = 0; j < num; j++)
                flash_memory[i * MAX_MENU2_NUM + j] = ex_float2int(*floatvalue[j]);
            break;
        case PARASET_S :
            for (j = 0; j < num; j++)
                flash_memory[i * MAX_MENU2_NUM + j] = *intvalue[j];
            break;
        }
    }
    flash_erase_page(0, 0);

    flash_write_page(0, 0, flash_memory, data_num);
}
